package cn.myfirefly.moming.house.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.myfirefly.moming.house.dao.mapper.SpfTradeContractWebimageMapper;
import cn.myfirefly.moming.house.entity.SpfTradeContractWebimage;
import cn.myfirefly.moming.house.model.SpfTradeContractWebimageDto;
import cn.myfirefly.core.BaseDao;
import cn.myfirefly.core.model.PageResultDto;

@Repository
public class SpfTradeContractWebimageDao extends BaseDao<SpfTradeContractWebimage> {
	
	@Autowired
	private SpfTradeContractWebimageMapper spfTradeContractWebimageMapper;
	
	public PageResultDto<SpfTradeContractWebimageDto> getList(SpfTradeContractWebimageDto dto) {
		PageResultDto<SpfTradeContractWebimageDto> resultDto = new PageResultDto<>();
		//分页处理
		Page<SpfTradeContractWebimageDto> page = PageHelper.startPage(dto.getPageCurrent(), dto.getPageSize(), true);
		List<SpfTradeContractWebimageDto> list = spfTradeContractWebimageMapper.getList(null);
		resultDto.setPageCurrent(dto.getPageCurrent());
		resultDto.setTotal((int)page.getTotal());
		resultDto.setList(list);
		return resultDto;
	}
	
	@SuppressWarnings("unchecked")
	public List<SpfTradeContractWebimage> getList(Integer contractId) {
		Session session = sessionFactory.getCurrentSession();
		StringBuffer querySql = new StringBuffer(" from SpfTradeContractWebimage t where t.tradeContractId=:tradeContractId ");
		Query query = session.createQuery(querySql.toString());
		query.setInteger("tradeContractId", contractId);
		return query.list();
	}
}
